package com.beordie.service.impl;

import com.beordie.dao.IMenuDao;
import com.beordie.dao.impl.MenuDaoImpl;
import com.beordie.model.Menu;
import com.beordie.model.Role;
import com.beordie.service.IMenuService;
import com.beordie.service.IRoleService;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname MenuServiceImpl
 * @Description TODO
 * @Date 2021/6/19 12:43
 * @Created 30500
 */
public class MenuServiceImpl implements IMenuService {
    private IMenuDao menuDao = new MenuDaoImpl();

    @Override
    public int getAllTotal() {
        return menuDao.getAllTotal();
    }

    @Override
    public List<Menu> getByLimit(int index, int pageSize) {
        return menuDao.getByLimit(index, pageSize);
    }

    @Override
    public List<Menu> getSecond() {
        List<Menu> menuList = menuDao.getAll();
        List<Menu> newList = new ArrayList<>();

        // 循环遍历取出二级菜单填充
        for (Menu menu : menuList) {
            if (menu.getUpMenuId() == 0) {
                List<Menu> newTemp = new ArrayList<>();
                for (Menu menuS : menuList) {
                    if (menu.getMenuId() == menuS.getUpMenuId()) {
                        newTemp.add(menuS);
                    }
                }
                menu.setSecond(newTemp);
                newList.add(menu);
            }
        }
        return newList;
    }
}
